package com.leyou.auth.interceptor;

import com.leyou.auth.scheduled.AppTokenScheduled;
import com.leyou.common.constants.LyConstants;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * RequestInterceptor 的作用是，只要当前服务要通过feign访问其他服务，都会被拦截
 */
@Component
public class AuthFeignInterceptor implements RequestInterceptor {

    @Autowired
    private AppTokenScheduled appTokenScheduled;

    @Override
    public void apply(RequestTemplate requestTemplate) {
        requestTemplate.header(LyConstants.APP_TOKEN_HEADER, appTokenScheduled.getToken());
    }
}
